package com.carb.controller.member;

import com.carb.dto.CarAddDTO;
import com.carb.dto.CarUpdateDTO;
import com.carb.entity.Car;
import com.carb.result.Result;
import com.carb.service.ICarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车辆管理 前端控制器
 * </p>
 *
 * @author XuChaoyang
 * @since 2025-01-18
 */
@RestController("memberCarController")
@RequestMapping("/member/car")
@Tag(name = "车辆管理相关接口")
@Slf4j
public class CarController {

    @Resource
    private ICarService carService;

    /**
     * 新增当前登录会员车辆
     * @param carAddDTO 新增车辆信息
     */
    @PostMapping("/add")
    @Operation(summary = "新增当前登录会员车辆")
    public Result<String> addCurrentMemberCar(@RequestBody CarAddDTO carAddDTO) {
        log.info("新增当前登录会员车辆：{}", carAddDTO);
        carService.addCurrentMemberCar(carAddDTO);
        log.info("新增当前登录会员车辆成功！");
        return Result.success();
    }

    /**
     * 查询当前登录会员所有车辆
     * @return 车辆列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询当前登录会员所有车辆")
    public Result<List<Car>> listMemberCar() {
        log.info("查询当前登录会员所有车辆");
        List<Car> carList = carService.listMemberCar();
        log.info("查询当前登录会员所有车辆成功！");
        return Result.success(carList);
    }

    /**
     * 修改当前登录会员车辆信息
     * @param carUpdateDTO 修改的车辆信息
     */
    @PutMapping
    @Operation(summary = "修改当前登录会员车辆信息")
    public Result<String> updateCurrentMemberCar(@RequestBody CarUpdateDTO carUpdateDTO) {
        log.info("修改当前登录会员车辆信息：{}", carUpdateDTO);
        carService.updateCurrentMemberCar(carUpdateDTO);
        log.info("修改当前登录会员车辆信息成功！");
        return Result.success();
    }

    /**
     * 删除当前登录会员车辆
     * @param id 车辆id
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除当前登录会员车辆")
    public Result<String> deleteCurrentMemberCar(@PathVariable @Parameter(description = "车辆id") Long id) {
        log.info("删除当前登录会员车辆，车辆id：{}", id);
        carService.deleteCurrentMemberCar(id);
        log.info("删除当前登录会员车辆成功！");
        return Result.success();
    }

}
